package com.lxp.kotlintest.view.news

import android.annotation.SuppressLint
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import com.lxp.kotlintest.R
import com.lxp.kotlintest.base.BaseActivity
import com.orhanobut.logger.Logger
import com.tencent.smtt.sdk.WebChromeClient
import com.tencent.smtt.sdk.WebViewClient
import kotlinx.android.synthetic.main.activity_news_details.*

class NewsDetailsActivity : BaseActivity() {
    private var mUrl: String? = null

    companion object {
        const val INTENT_NEWS_DETAILS_CODE_URL: String = "NEWS_DETAILS_URL"
    }

    override fun bindLayout(): Int {
        return R.layout.activity_news_details
    }

    override fun initParms(parms: Bundle?) {
        mUrl = parms?.get(INTENT_NEWS_DETAILS_CODE_URL).toString()

        Logger.d(mUrl + "")
    }

    @SuppressLint("SetJavaScriptEnabled")
    override fun initViews() {
        webView.settings.javaScriptEnabled = true
        webView.webChromeClient = WebChromeClient()
        webView.webViewClient = WebViewClient()
    }

    override fun doBusiness() {
        webView.loadUrl(mUrl)
    }

    override fun widgetClick(v: View?) {

    }

    override fun onBackPressed() {
        if (webView.canGoBack()) {
            webView.goBack()
        } else {
            super.onBackPressed()
        }
    }

}
